package com.jp.knowledge.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.my.model.SearchResultModel;

import java.util.List;

/**
 * @author gzejia 978862664@qq.com
 */
public class SearchListAdapter extends RecycleVAdapter<SearchResultModel> {

    public SearchListAdapter(Context context, @NonNull List<SearchResultModel> list) {
        super(context, list);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_search_data;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        SearchResultModel model = getData(position);
        holder.setTextView(R.id.item_data_tv_name, model.getName());
//        holder.setImageUrl(R.id.item_data_iv_logo, model.getIcon()
//                + "?imageView2/2/w/80/interlace/1");
        setTypeLabel(holder.getTextView(R.id.item_organize_type_label), model.getType());
    }

    private void setTypeLabel(TextView label, int type){
        label.setVisibility(View.VISIBLE);
        if(type == 1){
            label.setText("公司");
            label.setTextColor(mContext.getResources().getColor(R.color.theme_color));
            label.setBackground(mContext.getResources().getDrawable(R.drawable.organiza_type_label_blue));
        } else if(type == 2){
            label.setText("学校");
            label.setTextColor(mContext.getResources().getColor(R.color.pink));
            label.setBackground(mContext.getResources().getDrawable(R.drawable.organiza_type_label_pink));
        } else if(type == 3){
            label.setText("众创空间");
            label.setTextColor(mContext.getResources().getColor(R.color.orange));
            label.setBackground(mContext.getResources().getDrawable(R.drawable.organiza_type_label_orange));
        } else if(type == 4){
            label.setText("其他组织");
            label.setTextColor(mContext.getResources().getColor(R.color.green));
            label.setBackground(mContext.getResources().getDrawable(R.drawable.organiza_type_label_green));
        } else{
            label.setVisibility(View.GONE);
        }
    }
}
